<?php
namespace User\Controller;
use Common\Controller\AdminbaseController;
class ExternalController extends AdminbaseController {
	protected $qrcodeevent_model;

	function _initialize() {
		parent::_initialize();
		$this->qrcodeevent_model = D("QrcodeEvent");
		$this->qrcode_list_user_model = D("QrcodeListUser");
	}

    private function externalstatus() {
		$externalstatus =array(
			array(
	            array('id' => '1', 'name'=>'用户昵称'),
	            array('id' => '2', 'name'=>'设备ID'),
	            array('id' => '3', 'name'=>'扫码次数'),
	            array('id' => '4', 'name'=>'来源'),
			),
			array(
	            array('id' => '1','name'=>'后台创建二维码'),
	            array('id' => '2','name'=>'其他入口关注'),
			),
		);
		return $externalstatus;
    }
	function index(){
		$this->_lists();
		$this->display();
	}
	function _lists(){
			if(I('param.search')){
				$keyword =I('param.keyword');
				if(I('param.search') ==1){$search = "nickname like '%$keyword%'";}
				if(I('param.search') ==2){$search = "terminalid = '$keyword'";}
				if(I('param.search') ==3){$search = "hits  >= '$keyword'";}
				if(I('param.search') ==4){$search = "source like '%$keyword%'";}
				$_GET['search']=I('param.search');
				$_GET['keyword']=I('param.keyword');
			}
		$count=$this->qrcodeevent_model->where($search)->count();
		$page = $this->page($count, 50);
		$qrcodeevent=$this->qrcodeevent_model
		->where($search)
		->limit($page->firstRow . ',' . $page->listRows)
		->order("id DESC")->select();
		$estatus = $this->externalstatus();
		$this->assign("search",$estatus[0]);
    	$this->assign('page', $page->show('Admin'));
		$this->assign("qrcodeevent", $qrcodeevent);
		$this->assign("count", $count);
	}
	function attention(){
		$count=$this->qrcode_list_user_model->count();
		$page = $this->page($count, 50);
		$list=$this->qrcode_list_user_model
		->limit($page->firstRow . ',' . $page->listRows)
		->order("id DESC")->select();
		if($list){
			foreach($list as$ls){
				$source[] =$ls['source'];
			}
			$qlist=M("QrcodeList")->where(array('id'=>array('in',$source)))->select();
			$this->assign("qlist", $qlist);
		}
		$estatus = $this->externalstatus();
    	$this->assign('page', $page->show('Admin'));
		$this->assign("list", $list);
		$this->assign("count", $count);
		$this->assign("type",$estatus[1]);
		$this->display();
	}
}
